package com.yiren.dbaa.view.dialog;

import android.app.Activity;
import android.content.Intent;

/**
 * Created by WANGRONGXIANG
 * on 2020/11/18
 * Describe
 */
public class CheckNetworkDialog {

    public static void showCheckNetworkDialog(Activity activity, String content) {
        try {
            if (activity.isFinishing()) {
                return;
            }
            CustomDialog.Builder builder = new CustomDialog.Builder(activity);
//		        builder.setMessage("网络连接错误，请检查无线/移动网络是否已开启!");  
            builder.setMessage(content);
            builder.setTitle("系统提示");
            builder.setCanceled(false);
            builder.setPositiveButton("检查网络", (dialog, which) -> {
                if (android.os.Build.VERSION.SDK_INT > 10) {
                    // 3.0以上打开设置界面，也可以直接用ACTION_WIRELESS_SETTINGS打开到wifi界面
                    //跳到系统设置页面（目前友盟上出现一款机型（Generic android on ac8317）打不开系统设置）
//		        				((Activity) context).startActivity(new Intent(android.provider.Settings.ACTION_SETTINGS));
                    activity.startActivity(new Intent(android.provider.Settings.ACTION_WIFI_SETTINGS));
                } else {
                    //跳到数据流量开关页面
                    activity.startActivity(new Intent(android.provider.Settings.ACTION_WIFI_SETTINGS));
                }
                dialog.dismiss();
            });
            builder.setNegativeButton("取消", (dialog, which) -> {
                dialog.dismiss();
            });
            if (!activity.isFinishing()) {
                builder.create().show();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static void showCheckNetworkDialog2(Activity activity, String content) {
        try {
            if (activity.isFinishing()) {
                return;
            }
            CustomDialog.Builder builder = new CustomDialog.Builder(activity);
//		        builder.setMessage("网络连接错误，请检查无线/移动网络是否已开启!");
            builder.setMessage(content);
            builder.setTitle("系统提示");
            builder.setCanceled(false);
            builder.setPositiveButton("我知道了", (dialog, which) -> {
                dialog.dismiss();
            });
            if (!activity.isFinishing()) {
                builder.create().show();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
